<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>首页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/res/layui-v2.5.6/css/layui.css"
          media="all">
    <script type="text/javascript" src="/res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="/ok-admin/js/permissionSetting.js"></script>
    <link rel="stylesheet" href="/ok-admin/css/admin.css"
          media="all">
    <style type="text/css">
        /*滚动条样式*/okolidolid
        .innerbox::-webkit-scrollbar { /*滚动条整体样式*/
            width: 6px; /*高宽分别对应横竖滚动条的尺寸*/
            height: 6px;
        }

        .innerbox::-webkit-scrollbar-thumb { /*滚动条里面小方块*/
            border-radius: 10px;
            -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
            background: rgba(0, 0, 0, 0.2);
        }

        .innerbox::-webkit-scrollbar-track { /*滚动条里面轨道*/
            -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
            border-radius: 0;
            background: rgba(0, 0, 0, 0.1);
        }

        .layui-input {
            border: none;
        }

        .layui-col-md3 {
            width: 25%;
        }

        .zc {
            width: 100%;
            height: 30px;
            background-color: #F0F0F0;
            text-align: center;
        }

        #opeyion {
            color: blue;
        }

        .span {
            display: block;
            float: left;
            width: 46%;
            line-height: 30px;
            padding: 0px 2%;
        }

        .zc_centent {
            width: 100%;
            height: 30px;
            border-bottom: 1px dashed #c2c2c2;
        }

        .zc_centent:hover {
            background-color: #F0F0F0;
        }
    </style>
</head>
<body class="innerbox" onload="pdOne();pdTwo();">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">

        <div class="layui-col-sm6 layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-header">
                    库存预警<span class="layui-badge layui-bg-blue layuiadmin-badge">条</span>
                </div>
                <div class="layui-card-body layuiadmin-card-list">
                    <p class="layuiadmin-big-font" id="repertory_earlyWarning"></p>
                    <p>
                        <a href="#inventoryRecord" class="layui-btn layui-btn-xs">查看详情</a><span
                            class="layuiadmin-span-color"> <i
                            class="layui-inline layui-icon layui-icon-flag"></i></span>
                    </p>
                </div>
            </div>
        </div>
        <div class="layui-col-sm6 layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-header">
                    今日销量<span class="layui-badge layui-bg-cyan layuiadmin-badge">日</span>
                </div>
                <div class="layui-card-body layuiadmin-card-list">
                    <p class="layuiadmin-big-font" id="todaysSales"></p>
                    <p>
                        本月销量 <span class="layuiadmin-span-color" id="monthSales"><i
                            class="layui-inline layui-icon layui-icon-face-smile-b"></i></span>
                    </p>
                </div>
            </div>
        </div>
        <div class="layui-col-sm6 layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-header">
                    今日收入(纯收入) <span class="layui-badge layui-bg-green layuiadmin-badge">日</span>
                </div>
                <div class="layui-card-body layuiadmin-card-list">

                    <p class="layuiadmin-big-font" id="todaysIncome"></p>
                    <p>
                        本月收入(纯收入) <span class="layuiadmin-span-color" id="monthIncome"><i
                            class="layui-inline layui-icon layui-icon-rmb"></i></span>
                    </p>
                </div>
            </div>
        </div>
        <!-- <div class="layui-col-sm6 layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-header">
                    等待您审核 <span class="layui-badge layui-bg-orange layuiadmin-badge">条</span>
                </div>
                <div class="layui-card-body layuiadmin-card-list">

                    <p class="layuiadmin-big-font">66,666</p>
                    <p>
                        已审核 <span class="layuiadmin-span-color">15% <i
                            class="layui-inline layui-icon layui-icon-user"></i></span>
                    </p>
                </div>
            </div>
        </div> -->
        <div class="layui-col-sm6 layui-col-md3">
            <div class="layui-card">
                <div class="layui-card-header">
                    财务总金额<span class="layui-badge layui-bg-orange layuiadmin-badge">元</span>
                </div>
                <div class="layui-card-body layuiadmin-card-list">

                    <p class="layuiadmin-big-font sumMoney"></p>
                    <p>
                        财务总金额<span class="layuiadmin-span-color sumMoney"><i
                            class="layui-inline layui-icon layui-icon-rmb"></i></span>
                    </p>
                </div>
            </div>
        </div>
        <div class="layui-col-sm8" style="width:100%">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-sm6">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            药品年销售量占年总销售的百分比
                            <div class="layuiadmin-btn-group" style="position:absolute;top:0px;">
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input year" id="dateThree"
                                               placeholder="请选择年份" autocomplete="off"
                                               style="height:30px;width:120px;position:relative;top:-2px;left:-10px;">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-body" id="salesProportion" style="width:100%;height:316px">

                        </div>
                    </div>
                </div>
                <div class="layui-col-sm6">
                    <div class="layui-card">
                        <div class="layui-card-header">政策维护
                            <div class="layuiadmin-btn-group" style="centent_nrposition:absolute;top:0px;">
                                <input class="layui-btn layui-btn-xs" value="查看历史记录" id="cal">
                            </div>
                        </div>
                        <div class="layui-card-body innerbox"
                             style="overflow-x: auto; overflow-y: auto; height: 315px; width:94%;">
                            <!-- <table class="layui-table" lay-data="{height:315, url:'../../policy/findAll.action', page:true, id:'test',size:'sm'}" lay-filter="test">
                              <thead>
                                <tr>
                                  <th lay-data="{field:'policyName', width:80}">政策名称</th>
                                  <th lay-data="{field:'policyComment', width:80}">政策内容</th>
                                  <th lay-data="{field:'policyPerson', width:80}">政策发布人</th>
                                  <th lay-data="{field:'policyTime', width:80}">发布时间</th>
                                  <th lay-data="{field:'company_name', width:80}">公司名称</th>
                                </tr>
                              </thead>
                            </table> -->
                            <div class="zc">
                                <span class="span">政策标题</span>
                                <span class="span">发布时间</span>
                            </div>
                            <div id="centent">
                                <div id="centent_nr" direction="up" scrollamount="2" loop="infinite"
                                     style="width:100%;height:270px; text-align: center">

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-sm12">
            <div class="layui-card">
                <div class="layui-card-header">
                    销售量排名前十数据统计&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="layui-btn layui-btn-xs"
                                                                                  href="#tongji">查看详情</a>
                    <div class="layuiadmin-btn-group" style="position:absolute;top:0px;">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input year" id="dateOne"
                                       placeholder="请选择年份"
                                       style="height:30px;width:120px;position:relative;top:-2px;left:-10px;">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <div class="layui-row">
                        <div class="layui-col-sm8 innerbox" style="width:100%;overflow-x:auto;">
                            <div id="salesNumber" style="width:100%;height:400px;">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-sm12">
            <div class="layui-card">
                <div class="layui-card-header">
                    销售总金额与成本总金额对比图&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;&nbsp;销售总金额及毛利对比图
                    <div class="layuiadmin-btn-group" style="position:absolute;top:0px;">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input year" id="dateTwo"
                                       placeholder="请选择年份"
                                       style="height:30px;width:120px;position:relative;top:-2px;left:-10px;">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <div class="layui-row">
                        <div class="layui-col-sm8 innerbox" style="width:50%;overflow-x:auto;">
                            <div id="salesPrice" style="width:100%;height:400px;">

                            </div>
                        </div>
                        <div class="layui-col-sm4 innerbox" style="width:50%;overflow-x:auto;">
                            <div id="salesSumMoney" style="width:100%;height:400px;">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-sm8" style="width:100%">
            <div class="layui-row layui-col-space15">

                <div class="layui-col-sm6">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            <a name="tongji">销售量数排行表(每年每月的总销售量)</a>
                            <div class="layuiadmin-btn-group"
                                 style="position: absolute; top: 0px;">
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input year" id="dateFour"
                                               placeholder="请选择年份"
                                               style="height: 30px; width: 120px; position: relative; top: -2px; left: -10px;" autocomplete="off">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-body">
                            <table class="layui-table"
                                   lay-data="{height:315,method:'post', url:'/hqMarketdetail/findAllSalesStatistics?status=2', id:'SalesStatistics',size:'sm',totalRow: true,page: true}"
                                   lay-filter="test">
                                <thead>
                                <tr>
                                    <th lay-data="{field:'drugName', width:100,totalRowText: '合计：',fixed:'left'}">药品名称
                                    </th>
                                    <th lay-data="{field:'oneMonth', width:80,totalRow: true}">1月</th>
                                    <th lay-data="{field:'twoMonth', width:80,totalRow: true}">2月</th>
                                    <th lay-data="{field:'threeMonth', width:80,totalRow: true}">3月</th>
                                    <th lay-data="{field:'fourMonth', width:80,totalRow: true}">4月</th>
                                    <th lay-data="{field:'fiveMonth', width:80,totalRow: true}">5月</th>
                                    <th lay-data="{field:'sixMonth', width:80,totalRow: true}">6月</th>
                                    <th lay-data="{field:'sevenMonth', width:80,totalRow: true}">7月</th>
                                    <th lay-data="{field:'eightMonth', width:80,totalRow: true}">8月</th>
                                    <th lay-data="{field:'nineMonth', width:80,totalRow: true}">9月</th>
                                    <th lay-data="{field:'tenMonth'}, width:80,totalRow: true">10月</th>
                                    <th lay-data="{field:'elevenMonth', width:80,totalRow: true}">11月</th>
                                    <th lay-data="{field:'twelveMonth', width:80,totalRow: true}">12月</th>
                                    <th lay-data="{field:'sumNumber', width:80,totalRow: true}">年销量</th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="layui-col-sm6">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            财务记录信息
                            <div class="layuiadmin-btn-group layui-form" style="position: absolute; top: 0px;">
                                <div class="layui-input-inline" style="width:120px;">
                                    <select name="FinancialRecord" lay-verify="" lay-search lay-filter="type">
                                        <option value="">收入/支出</option>
                                        <option value="1">收入</option>
                                        <option value="2">支出</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-body">
                            <table id="caiwu" lay-filter="test"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-sm8" style="width:100%">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-sm6">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            <a name="inventoryRecord"><a href="javascript:;" class="yujing" id="drugRepertory"
                                                         style="border-bottom:	2px solid #5FB878;padding-bottom:4px;">药品库存预警</a></a><span
                                id="gang">&nbsp;&nbsp;/&nbsp;&nbsp;</span><a href="javascript:;" class="yujing"
                                                                             id="materialsRepertory"
                                                                             style="padding-bottom:2px;">材料库存预警</a>
                            <div class="layuiadmin-btn-group layui-form" style="position: absolute; top: 0px;">
                                <div class="layui-input-inline" style="width:120px;">
                                    <button id="addOrDetails" name="drugSalesProportion" class="layui-btn layui-btn-xs">
                                        添加生产计划单
                                    </button>
                                    <button id="addOrDetailsss" name="materialsRepertory"
                                            class="layui-btn layui-btn-xs">添加采购单
                                    </button>
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-body" id="drugSalesProportion">
                            <table class="layui-table"
                                   lay-data="{height:315,method:'post', url:'/hqInventory/findAllDrugEarlyWarning', page:true, id:'drugLackOfStock',size:'sm',parseData:function(res){ypyj=res.redAlert}}"
                                   lay-filter="drugLackOfStock" style="display:none">
                                <thead>
                                <tr>
                                    <th lay-data="{field: 'drugName', sort: 'true', align: 'center', width:182,templet:function(d){
                                    return ypyj>=d.inventoryNum?'<font color=red>'+d.drugName+'</font>':d.drugName;}}">药品名称
                                    </th>
                                    <th lay-data="{field: 'typeName', sort: 'true', align: 'center'}">药品类型</th>
                                    <th lay-data="{field: 'inventoryNum', sort: 'true', align: 'center', width:160}">
                                        数量
                                    </th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                        <div class="layui-card-body" id="materialsSalesProportion" style="display:none">
                            <table class="layui-table"
                                   lay-data="{height:315, url:getRootPath()+'hqInventory/findMaterialsWarning',method: 'post', page:true, id:'findMaterialsWarning',size:'sm',parseData:function(res){yclyj=res.redAlert}}"
                                   lay-filter="materialsLackOfStock" style="display:none">
                                <thead>
                                <tr>
                                    <th lay-data="{field: 'materialName', align: 'center', width:182,templet:function(d){
                                    return yclyj>=d.count?'<font color=red>'+d.materialName+'</font>':d.materialName;}}">材料名称</th>
                                    <th lay-data="{field: 'typeName', align: 'center', width:120}">材料类型</th>
                                    <th lay-data="{field: 'count', sort: 'true', align: 'center', width:160}">数量</th>
                                    <!--                                    <th lay-data="{align: 'center', width:160, toolbar: '#barDemoTwo'}">操作</th>-->
                                </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                </div>
                <!--   药品跟原材料库存明细展示    -->
                <div class="layui-col-sm6">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            <a id="mingxi"><a href="javascript:;" class="mingxi" id="drugInventory"
                                              style="border-bottom:2px solid #5FB878;padding-bottom:4px;">药品库存明细</a></a><span
                                id="nbsp">&nbsp;&nbsp;/&nbsp;&nbsp;</span><a href="javascript:;" class="mingxi"
                                                                             id="materialsInventory"
                                                                             style="padding-bottom:2px;">原材料库存明细</a>
                            <div class="layuiadmin-btn-group layui-form" style="position: absolute; top: 0px;">
                                <div class="layui-input-inline" style="width:120px;">
                                    <select name="state" lay-verify="" lay-search style="border:none;"
                                            lay-filter="type">
                                        <option value="">入库/出库</option>
                                        <option value="1">入库</option>
                                        <option value="2">出库</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-body" id="yaopin">
                            <table class="layui-table" lay-data="{height:315,totalRow: true, url:getRootPath()+'hqInventory/drugDetails?id='+returnUser().companyId, page:true, method: 'post', id:'drugDetails',size:'sm', parseData: function (res) {
                var jin=0;
                $.each(res.data,function(index,item){
                    jin+=item.count
                });return {'code': res.code, //解析接口状态
                                'count': res.count, //解析数据长度
                                'msg':res.msg,
                                'data':res.data,
                                'totalRow':{
                                    count:Math.round(jin)
                                }};}}" lay-filter="drugLackOfStock" style="display:none">
                                <thead>
                                <tr>
                                    <th lay-data="{field: 'drugName', align: 'center', width:110, totalRowText: '合计'}">
                                        药品名称
                                    </th>
                                    <th lay-data="{field: 'count', sort: 'true', align: 'center', width:130, totalRow: true}">
                                        数量
                                    </th>
                                    <th lay-data="{field: 'typeName', align: 'center', width:110}">药品类型</th>
                                    <th lay-data="{field: 'state', align: 'center', width:80, templet: function (d) {
                                            return d.state === 1 ? '入库' : '出库';
                                    }}">状态
                                    </th>
                                    <th lay-data="{field: 'optime', sort: 'true', align: 'center', width:160}">操作时间</th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                        <div class="layui-card-body" id="yuancailiao" style="display:none">
                            <table class="layui-table" lay-data="{height:315,totalRow: true, url:getRootPath()+'hqInventory/materialsDetails?id='+returnUser().companyId, page:true, method: 'post', id:'materialsDetails',size:'sm', parseData: function (res) {
                var jin=0;
                $.each(res.data,function(index,item){
                    jin+=item.inventoryNum
                });return {'code': res.code, //解析接口状态
                                'count': res.count, //解析数据长度
                                'msg':res.msg,
                                'data':res.data,
                                'totalRow':{
                                    inventoryNum:Math.round(jin)
                                }};}}" lay-filter="materialsLackOfStock" style="display:none">
                                <thead>
                                <tr>
                                    <th lay-data="{field: 'materialName', align: 'center', width:110, totalRowText: '合计'}">
                                        材料名称
                                    </th>
                                    <th lay-data="{field: 'inventoryNum', sort: 'true', align: 'center', width:130, totalRow: true}">
                                        数量
                                    </th>
                                    <th lay-data="{field: 'typeName', align: 'center', width:110}">材料类型</th>
                                    <th lay-data="{field: 'state', align: 'center', width:80, templet: function (d) {
                                            return d.state === 1 ? '入库' : '出库';
                                    }}">状态
                                    </th>
                                    <th lay-data="{field: 'optime', sort: 'true', align: 'center', width:160}">操作时间</th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

<script src="/res/layui-v2.5.6/layui.js"></script>
<script type="text/javascript" src="../../res/js/base.js"></script>
<script type="text/javascript" src="../lib/echarts/echarts.min.js"></script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="ck">查看记录详情</a>
</script>
<script type="text/html" id="barDemos">
    <a class="layui-btn layui-btn-xs" lay-event="detail">查看记录详情</a>
</script>
<script type="text/html" id="barDemoOne">
    <a class="layui-btn layui-btn-xs" lay-event="production" name="production" onclick="add(this);" num="0"
       itemName="{{d.itemName}}" drugId="{{d.pwId}}">加入生产计划单</a>
</script>
<script type="text/html" id="barDemoTwo">
    <a class="layui-btn layui-btn-xs" lay-event="purchase">加入采购单</a>
</script>
<script src="/res/js/util.js"></script>
<script type="text/javascript">
    var ypyj=null;
    var yclyj=null;
    let users = JSON.parse(window.localStorage.getItem("users"));
    $(function () {
        var myDate = new Date();//获取系统当前时间

        //销售量排名前十数据统计
        //如果日期为空取当前年份
        var salesDrugAllBeforeTen = null;
        if ($("#dateTwo").val() == null || $("#dateTwo").val() == '') {
            let value = myDate.getFullYear();
            salesDrugAllBeforeTen = {"salesYear": value, "status": "1","page":1, "limit": 10};
        }
        chartOne(salesDrugAllBeforeTen);

        //如果日期为空取当前年份
        var salesProfit = null;
        if ($("#dateTwo").val() == null || $("#dateTwo").val() == '') {
            let value = myDate.getFullYear();
            salesProfit = {"salesYear": value};
        }
        chartTwo(salesProfit);
        chartThree(salesProfit);
        // var data = {"page":1,"limit":6,"num":1};
        // var data = {"page":1,"limit":6,"num":2};


        var drugMarketData = null;
        if ($("#dateThree").val() == null || $("#dateThree").val() == '') {
            let value = myDate.getFullYear();
            drugMarketData = {"filId": 1, "page": 1, "limit": 10, "salesYear": value};
        }
        chartFour(drugMarketData);

    });

    function chartOne(data) {
        var url = getRootPath() + "hqMarketdetail/findAllSalesStatistics";
        $.post(url, data, function (msg) {
            console.info(msg)
            var salesNumber = echarts.init(document.getElementById('salesNumber'));
            option = {
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        label: {
                            backgroundColor: '#333'
                        }
                    }
                },
                legend: {
                    data: msg.drugAllName
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                grid: {
                    left: '1%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: [
                    {
                        type: 'category',
                        boundaryGap: false,
                        data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: msg.list
            };
            // 使用刚指定的配置项和数据显示图表。
            salesNumber.setOption(option);
        });
    }

    function chartTwo(data) {
        var url = getRootPath() + "hqMarketdetail/findTotalCostAllPriceAndSalesProfit";
        $.post(url, data, function (msg) {
            var salesPrice = echarts.init(document.getElementById('salesPrice'));
            option = {
                //color: ['#3398DB'],
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['销售总金额', '成本总金额']
                },
                grid: {
                    left: '1%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                xAxis: [
                    {
                        type: 'category',
                        data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
                        boundaryGap: false,
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        name: '销售总金额',
                        type: 'line',
                        data: msg.totalSales
                    }, {
                        name: '成本总金额',
                        type: 'line',
                        data: msg.cost
                    }
                ]
            };
            // 使用刚指定的配置项和数据显示图表。
            salesPrice.setOption(option);
            chartThree(msg);
        }, "json");
    }

    function chartThree(msg) {
        // var url = getRootPath()+"hqMarketdetail/findTotalCostAllPriceAndSalesProfit";
        // $.post(url,data,function(msg){
        var salesSumMoney = echarts.init(document.getElementById('salesSumMoney'));
        option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            legend: {
                data: ['销售总金额', '毛利']
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: '销售总金额',
                    type: 'bar',
                    stack: '金额',
                    data: msg.totalSales
                },
                {
                    name: '毛利',
                    type: 'bar',
                    stack: '金额',
                    data: msg.grossMargin
                }
            ]
        };

        // 使用刚指定的配置项和数据显示图表。
        salesSumMoney.setOption(option);
        // },"json");
    }

    function chartFour(data) {
        var url = "/hqMarketdetail/selectMarketFrontShi";
        console.info(data);
        $.post(url, data, function (msg) {
            var salesProportion = echarts.init(document.getElementById('salesProportion'));
            option = {
                title: {
                    text: '排行前十药品年销量占总销量的百分比',
                    x: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    type: 'scroll',
                    orient: 'vertical',
                    right: 10,
                    top: 20,
                    bottom: 20
                },
                series: [
                    {
                        name: '药品名称',
                        type: 'pie',
                        radius: '55%',
                        // roseType: 'angle',
                        center: ['50%', '50%'],
                        data: msg,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            // 使用刚指定的配置项和数据显示图表。
            salesProportion.setOption(option);
        }, "json");
    }

</script>
<script type="text/javascript">
    //初始化数据表格
    layui.use('table', function () {
        var table = layui.table;
        //初始化 判断是否为总公司
        if (returnUser().companyId !== "0") {
            $("#materialsInventory").hide()
            $("#drugInventory").attr("style", "")
            $("#drugRepertory").attr("style", "")
            $("#materialsRepertory").hide()
            $("#nbsp").hide()
            $("#gang").hide()
            $("#addOrDetails").text("添加采购计划单");
            if (!authorization("jurisdiction:purchaseDrug")) {
                $("#addOrDetailsss").addClass("layui-btn-disabled");
                $("#addOrDetailsss").attr("disabled", true);
            }
        }else {
            if (!authorization("jurisdiction:production")) {
                $("#addOrDetails").addClass("layui-btn-disabled");
                $("#addOrDetails").attr("disabled", true);
            }
        }

        /**
         * 财务明细
         */
        table.render({
            elem: '#caiwu'
            , url: getRootPath() + 'hqRicher/findCompanyFinancialDetails' //数据接口
            , page: true //开启分页
            , height: 315
            , size: 'sm'
            , totalRow: true  //开启合计
            , method: 'post'
            , cols: [[ //表头
                //{type: 'checkbox', fixed: 'left'}
                //{field: 'chargeoffId', title: '财务明细Id', width: 100, fixed: 'left', align: 'center'}
                {
                    field: 'state', title: '支出/收入', width: 120, align: 'center', templet: function (d) {
                        return d.state === 2 ? "支出" : "收入";
                    }, totalRowText: '合计'
                }, {field: 'chargeoffMoney', title: '明细金额', width: 120, align: 'center', totalRow: true}
                , {field: 'remark', title: '明细备注', width: 120, align: 'center'}
                , {field: 'operator', title: '操作人', width: 120, align: 'center'}
                , {field: 'optime', title: '操作时间', width: 144, align: 'center'}
                , {fixed: 'right', title: '查询信息', width: 130, align: 'center', toolbar: '#barDemos'}
            ]]
            , id: 'test'
            , parseData: function (res) {//res 即为原始返回的数据
                var jin = null;
                var chu = null;
                $.each(res.data, function (index, item) {
                    if (item.state === 1) {
                        jin += item.chargeoffMoney
                    } else {
                        chu += item.chargeoffMoney
                    }
                });
                return {
                    "code": res.code, //解析接口状态
                    "count": res.count, //解析数据长度
                    "msg": res.msg,
                    "data": res.data,
                    "totalRow": {
                        chargeoffMoney: jin - chu
                    }
                };
            }
        });
    });
</script>
<script>
    var openIndex = null;
    layui.use(['laydate', 'table', 'form'], function () {
        var laydate = layui.laydate
            , table = layui.table
            , form = layui.form;
        laydate.render({
            elem: '#dateOne'
            , type: 'year'
            , done: function (value, date, endDate) {
                /*  console.log(value); //得到日期生成的值，如：2017-08-18
                 console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                 console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。 */
                var data = null;
                data = { "page": 1, "limit": 10, "status": "1", "salesYear": value};
                chartOne(data);
            }
        });

        laydate.render({
            elem: '#dateTwo'
            , type: 'year'
            , done: function (value, date, endDate) {
                /* console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。 */
                var data = {"filId": 1, "page": 1, "limit": 6, "num": 1, "salesYear": value};
                chartTwo(data);
                var data = {"filId": 1, "page": 1, "limit": 6, "num": 2, "salesYear": value};
                chartThree(data);
            }
        });
        laydate.render({
            elem: '#dateThree'
            , type: 'year'
            , done: function (value, date, endDate) {
                /* console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。 */
                console.info(value);
                var data = {"filId": 1, "page": 1, "limit": 10, "salesYear": value};
                chartFour(data);
            }
        });
        laydate.render({
            elem: '#dateFour'
            , type: 'year'
            , done: function (value, date, endDate) {
                /*  console.log(value); //得到日期生成的值，如：2017-08-18
                 console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                 console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。 */
                table.reload('SalesStatistics', {
                    page: {
                        curr: 1
                    },
                    where: {
                        salesYear: value
                    }
                });
            }
        });

        table.on('tool(test)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var title = "";
            var url = "";
            if (layEvent === 'ck') { //查看
                title = "库存记录详情";
                var pwId = data.pwId;
                var irType = data.irType;
                alert("业务ID" + pwId + " 记录类型  " + irType);
                //alert("pwId:"+pwId+"  frType:"+frType);
                if (irType == "零售") {
                    alert("零售");
                    url = "ZgsSellDetailShowList.html?soId=" + pwId;
                } else if (irType == "批发") {
                    alert("批发");
                    url = "ZgsSellDetailShowList.html?soId=" + pwId;
                } else if (irType == "总店销售") {
                    alert("总店销售");
                    url = "ZgsSellDetailShowList.html?soId=" + pwId;
                } else if (irType == "药品入库") {
                    alert("质检入库");
                    url = "ZgsSellDetailShowList.html?soId=" + pwId;
                }
            } else if (layEvent == 'detail') {
                title = "财务记录详情";
                console.info(data);
                //查看原材料
                if (data.purchaseId != null) {
                    var url = "purchaseorder/purchasedetails.html?purchaseId=" + data.purchaseId;
                    layer.open({
                        type: 2,
                        area: ['76%', '75%'],//弹出框大小
                        shift: 1,//弹出框动画效果
                        content: [url, 'on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    });
                } else {
                    var id = data.drugId;
                    if (data.state===1){
                        openIndex = layer.open({
                            type: 2,
                            skin: 'layui-layer-rim', //加上边框
                            area: ['75%', '75%'], //宽高
                            title: '采购明细',
                            maxmin: true, //开启最大化最小化按钮
                            content: '../pages/ImmSell/wholesale.html?sellId=' + id,
                        });
                    }else {
                        openIndex = layer.open({
                            type: 2,
                            skin: 'layui-layer-rim', //加上边框
                            area: ['75%', '75%'], //宽高
                            title: '采购明细',
                            maxmin: true, //开启最大化最小化按钮
                            content: '../pages/immPurchase/immPurchaseDeatis.html?id=' + id,
                        });
                    }
                }
                return;
            }
            layer.open({
                type: 2,
                title: title,
                area: ['80%', '85%'],//弹出框大小
                shift: 1,//弹出框动画效果
                content: url //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            });
        });
        var array = new Array();
        table.on('tool()', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent == 'production') {
                alert('您点击了去生产');
            } else if (layEvent == 'purchase') {
                //加入采购单
                console.info(data);
                let num = 0;
                $.each(array, function (index, item) {
                    if (item === data.materialId) {
                        obj.tr[0].children[3].children[0].children[0].text = '加入采购单';
                        array.splice(index, 1);
                        num++;
                    }
                });
                if (num === 0) {
                    array.push(data.materialId)
                    obj.tr[0].children[3].children[0].children[0].text = '取消加入';
                }
                console.info(array);
            }
        })

        var $ = layui.$;
        $(".layui-icon-search").click(function (event) {
            var value = $("#InventoryRecord").val();
            table.reload('InventoryRecord', {
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: { //设定异步数据接口的额外参数，任意设
                    matName: value
                }
            });
        });

        form.on('select(type)', function (data) {
            /* console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象 */
            var name = $(data.elem).attr("name");
            console.info(name);
            if (name === "InventoryRecord") {
                table.reload('InventoryRecord', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: { //设定异步数据接口的额外参数，任意设
                        irType: data.value
                    }
                });
            } else if (name === "FinancialRecord") {
                table.reload('test', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: { //设定异步数据接口的额外参数，任意设
                        state: data.value
                    }
                });
            } else if (name === "state") {
                //刷新原材料库存明细
                table.reload('materialsDetails', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: { //设定异步数据接口的额外参数，任意设
                        state: data.value
                    }
                });
                table.reload('drugDetails', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: { //设定异步数据接口的额外参数，任意设
                        state: data.value
                    }
                });
            }
        });

        /* //查看政策维护详情
        $("#policyDetail").on('click',function(){
            //../wsz/PolicyList.html
            layer.open({
                  title: '政策维护'
                  ,type:2
                  ,area:['80%','80%']
                  ,content: '../wsz/PolicyList.html'
                });
        }); */

        //查询今日销量
        findTodaysSalesOrMonthSales(1);
        //查询月销量
        findTodaysSalesOrMonthSales(2);
        //查询今日收入
        findTodaysIncomeOrMonthIncome(1);
        //查询月收入
        findTodaysIncomeOrMonthIncome(2);

        //查询财务总金额
        var url = getRootPath() + "hqRicher/findSumMoney";
        $.ajax({
            url: url,
            data: null,
            type: 'post',
            success: function (msg) {
                $(".sumMoney").prepend(msg);
            }
        });

        //查询库存预警的个数
        $.ajax({
            url: getRootPath() + "hqInventory/findCount",
            data: null,
            type: 'post',
            success: function (msg) {
                $("#repertory_earlyWarning").text(msg);
            }
        });

        //查询政策维护
        findAll();

        $("#addOrDetails").attr("numOne", sessionStorage['numOne']);
        $("#addOrDetails").attr("numTwo", sessionStorage['numTwo']);
        var proId = $("#addOrDetails").attr("numOne");
        var poId = $("#addOrDetails").attr("numTwo");
        //库存明细查询
        $(".mingxi").on("click", function (event) {
            var id = $(event.target).attr("id");
            console.info(id);
            //药品明细
            if (id === "drugInventory") {
                $("#yaopin").show();
                $("#yuancailiao").hide();
                if (returnUser().companyId === "0") {
                    $("#materialsInventory").attr("style", "border-bottom:none");
                    $("#drugInventory").attr("style", "border-bottom:2px solid #5FB878;padding-bottom:4px;");
                }

            } else {
                $("#yuancailiao").show();
                $("#yaopin").hide();
                $("#drugInventory").attr("style", "border-bottom:none");
                $("#materialsInventory").attr("style", "border-bottom:2px solid #5FB878;padding-bottom:4px;");
            }
        });
        //预警查询
        $(".yujing").on('click', function (event) {
            var id = $(event.target).attr("id");
            console.info(id);
            if (id == "drugRepertory") {
                $("#addOrDetails").show();
                $("#addOrDetailsss").hide();
                $("#materialsSalesProportion").hide();
                $("#drugSalesProportion").show();
                if (whetherZGS()) {
                    $("#drugRepertory").attr("style", "border-bottom:2px solid #5FB878;padding-bottom:4px;");
                    $("#materialsRepertory").attr("style", "");
                    $("#materialsRepertory").show();
                    $("#gang").show();
                    $("#addOrDetails").text("添加生产计划单");
                    if (!authorization("jurisdiction:production")) {
                        $("#addOrDetails").addClass("layui-btn-disabled");
                        $("#addOrDetails").attr("disabled", true);
                    }
                } else {
                    $("#materialsRepertory").hide();
                    $("#gang").hide();
                    $("#addOrDetails").text("添加采购计划单");
                    if (!authorization("jurisdiction:purchaseDrug")) {
                        $("#addOrDetailsss").addClass("layui-btn-disabled");
                        $("#addOrDetailsss").attr("disabled", true);
                    }
                }

            } else if (id === "materialsRepertory") {
                $("#addOrDetails").text("添加采购单");
                $("#addOrDetails").attr("disabled", false);
                $("#addOrDetails").removeClass("layui-btn-disabled")
                $("#addOrDetails").hide();
                $("#addOrDetailsss").show();
                $("#drugSalesProportion").hide();
                $("#drugRepertory").attr("style", "border-bottom:none");
                $("#materialsSalesProportion").show();
                $("#materialsRepertory").attr("style", "border-bottom:2px solid #5FB878;padding-bottom:4px;");
                //权限
            }

        });
        // var name = $("#addOrDetails").attr("name");
        // if(name == "drugSalesProportion"){
        //     if($("#addOrDetails").attr("numOne") != ""){
        //         $("#addOrDetails").text("查看生产计划单详情");
        //         $("#addOrDetails").attr("typeOne","detail");
        //     }else {
        //         $("#addOrDetails").text("添加生产计划单");
        //         $("#addOrDetails").attr("typeOne","add");
        //     };
        // }else{
        //     if($("#addOrDetails").attr("numTwo") != ""){
        //         $("#addOrDetails").text("查看采购单详情");
        //         $("#addOrDetails").attr("typeTwo","detail");
        //     }else {
        //         $("#addOrDetails").text("添加采购单详情");
        //         $("#addOrDetails").attr("typeTwo","add");
        //     };
        // }
        //原材料预警采购
        $("#addOrDetailsss").on('click', function (event) {
            var names = $(event.target).attr("name");
            if (names==="materialsRepertory"){
                openIndex = layer.open({
                    title: "原材料采购单",
                    type: 2,
                    area: ["80%", "80%"],
                    shift: 1,//弹出框动画效果
                    content: ['purchaseorder/MaterialsWarningAdd.html', 'on']
                });
            }
        })
        //药品预警采购
        $("#addOrDetails").on('click', function (event) {
            var names = $(event.target).attr("name");
            var na = $(event.target).text();
            console.info(na);


            if (na == "添加采购计划单") {
                openIndex = layer.open({
                    title: "添加采购计划单",
                    type: 2,
                    area: ["80%", "80%"],
                    content: "immPurchase/addPurchasePlan.html"
                });
            }else{
                openIndex = layer.open({
                    title: "药品生产计划单",
                    type: 2,
                    area: ["100%", "100%"],
                    content: "manufacturePlan/addOrUpdate.html"
                });
            }
        });
    });



    function closeOpen(msg) {
        layer.close(openIndex);
        layer.msg(msg, {time: 1500})
    }

    function findTodaysSalesOrMonthSales(data) {
        var url = getRootPath() + "hqMarket/findTodaysSalesOrMonthSales";
        $.ajax({
            url: url,
            data: data,
            type: 'post',
            success: function (res) {
                if (data === 1) {
                    $("#todaysSales").prepend(res[1]);
                } else if (data === 2) {
                    $("#monthSales").prepend(res[0]);
                }
            }
        });
    }

    $("#cal").on("click", function () {
        layui.use('layer', function () {
            var layer = layui.layer; //弹层
            layer.open({
                type: 2,
                title: '发布记录',
                area: ['80%', '85%'],//弹出框大小
                shift: 1,//弹出框动画效果
                content: '../pages/maintenance/record.html'    //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            });
        });
    })

    function findTodaysIncomeOrMonthIncome(data) {
        var url = getRootPath() + "hqRicher/findTodayIncomeOrMonthIncome";
        $.ajax({
            url: url,
            data: null,
            type: 'post',
            success: function (res) {
                if (data === 1) {
                    $("#todaysIncome").prepend(res[1]);
                } else if (data === 2) {
                    $("#monthIncome").prepend(res[0]);
                }
            }
        });
    }

    function findAll() {
        var url = "/inform/selectAllInform";
        var data = {"page": 1, "limit": 20};
        $.ajax({
            url: url,
            data: data,
            asycn: false,
            success: function (msg) {
                for (var i = 0; i < msg.length; i++) {
                    $("#centent_nr").append("<a href='javascript:ckzcwh(\"" + msg[i].informId + "\");'><div class='zc_centent'><span class='span' >" + msg[i].informName + "</span>"
                        + "<span class='span' >" + msg[i].optime + "</span></div></a>");
                }
            }
        });
    }

    function ckzcwh(obj) {
        layui.use('layer', function () {
            var layer = layui.layer; //弹层
            layer.open({
                type: 2,
                title: false,
                shadeClose: true,
                scrollbar: false,
                area: ['90%', '95%'],//弹出框大小
                shift: 1, //弹出框动画效果
                content: '../pages/maintenance/moblie.html?informId=' + obj //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            });
        });
    }

    function pdOne() {
        var proId = $("#addOrDetails").attr("numOne");
        var url = getRootPath() + "SalesStatistics/findByProIds.action";
        var data = {"proId": proId};
        if (proId != "") {
            $.ajax({
                url: url,
                data: data,
                success: function (msg) {
                    for (var i = 0; i < msg.length; i++) {
                        /* $(obj).attr("num","1");
                        $(obj).text("取消加入生产计划单");
                        $(obj).attr("pwId",drpId); */
                        $("#" + msg[i].drugId).attr("num", 1);
                        $("#" + msg[i].drugId).text("取消加入生产计划单");
                        $("#" + msg[i].drugId).attr("pwId", msg[i].drpId);
                    }
                },
                dataType: "JSON"
            });
        }

    }

    function pdTwo() {
        var poId = $("#addOrDetails").attr("numTwo");
        var url = getRootPath() + "SalesStatistics/findByPoIds.action";
        var data = {"poId": poId};
        if (poId != "") {
            $.ajax({
                url: url,
                data: data,
                success: function (msg) {
                    for (var i = 0; i < msg.length; i++) {
                        $("#" + msg[i].matId).attr("num", 1);
                        $("#" + msg[i].matId).text("取消加入采购单");
                        $("#" + msg[i].matId).attr("pwId", msg[i].pobId);
                        /* $(obj).attr("num","1");
                        $(obj).text("取消加入采购单");
                        $(obj).attr("pwId",pobId); */
                    }
                },
                dataType: "JSON"
            });
        }

    }
</script>

</body>
</html>